package com.dlb.andorid.activity;

import androidx.viewpager.widget.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlb.andorid.R;
import com.dlb.andorid.fragment.CarFragment;
import com.dlb.andorid.fragment.HomeFragment;
import com.dlb.andorid.fragment.MineFragment;
import com.dlb.andorid.fragment.TypeFragment;
import com.kwan.xframe.common.adatper.CommonFragmentPageAdapter;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseActivity;
import com.zhy.autolayout.AutoLinearLayout;

public class MainActivity extends BaseActivity implements View.OnClickListener, ViewPager.OnPageChangeListener {

	@Override
	protected BasePresenter getBasePresenter() {
		return null;
	}

	@Override
	protected int getRootBottomViewId() {
		return 0;
	}

	@Override
	protected int getTitleBarViewId() {
		return 0;
	}

	@Override
	protected int getContentViewId() {
		return R.layout.activity_main;
	}


	public ViewPager vp_content;
	private AutoLinearLayout ll_tab_home, ll_tab_mine, ll_tab_car, ll_tab_type;
	private ImageView iv_tab_home, iv_tab_mine, iv_tab_car, iv_tab_type;
	private TextView tv_tab_home, tv_tab_mine, tv_tab_car, tv_tab_type;
	private View dot_notice;
	public CommonFragmentPageAdapter mPageAdapter;

	public TypeFragment mTypeFragment;

	@Override
	protected void initViews() {
		dot_notice = findViewById(R.id.dot_notice);
		vp_content = findViewById(R.id.vp_content);
		ll_tab_home = findViewById(R.id.ll_tab_home);
		ll_tab_mine = findViewById(R.id.ll_tab_mine);
		ll_tab_car = findViewById(R.id.ll_tab_car);
		ll_tab_type = findViewById(R.id.ll_tab_type);

		iv_tab_home = findViewById(R.id.iv_tab_home);
		iv_tab_mine = findViewById(R.id.iv_tab_mine);
		iv_tab_car = findViewById(R.id.iv_tab_car);
		iv_tab_type = findViewById(R.id.iv_tab_type);

		tv_tab_home = findViewById(R.id.tv_tab_home);
		tv_tab_mine = findViewById(R.id.tv_tab_mine);
		tv_tab_car = findViewById(R.id.tv_tab_car);
		tv_tab_type = findViewById(R.id.tv_tab_type);

		ll_tab_home.setOnClickListener(this);
		ll_tab_mine.setOnClickListener(this);
		ll_tab_car.setOnClickListener(this);
		ll_tab_type.setOnClickListener(this);

		mPageAdapter = new CommonFragmentPageAdapter(getSupportFragmentManager());

		mPageAdapter.addFragment(HomeFragment.newInstance(), "home");
		mPageAdapter.addFragment(CarFragment.newInstance(), "car");

		mTypeFragment = TypeFragment.newInstance();

		mPageAdapter.addFragment(mTypeFragment, "type");
		mPageAdapter.addFragment(MineFragment.newInstance(), "mine");

		vp_content.addOnPageChangeListener(this);
		vp_content.setAdapter(mPageAdapter);
		//onPageSelected(0);
		vp_content.setCurrentItem(0);
	}

	@Override
	protected void initViewSetting() {

	}

	@Override
	protected void initData() {

	}

	@Override
	protected String getTitleTxt() {
		return null;
	}

	@Override
	public String getPageName() {
		return null;
	}

	@Override
	public void onClick(View v) {
		if (v == ll_tab_home) {
			vp_content.setCurrentItem(0);
		} else if (v == ll_tab_car) {
			vp_content.setCurrentItem(1);
		} else if (v == ll_tab_type) {
			TypeFragment.classId = 1;
			vp_content.setCurrentItem(2);

		} else if (v == ll_tab_mine) {

//			if (!SPUtil.getIsLogin()) {
//				go2Activity(LoginActivity.class, null, false);
//				return;
//			}
			vp_content.setCurrentItem(3);

		}
	}

	@Override
	public void onPageScrolled(int i, float v, int i1) {

	}
	int currentPosition = 0;
	@Override
	public void onPageSelected(int position) {
		currentPosition = position;
		switch (position) {
			case 0:

				iv_tab_home.setImageResource(R.mipmap.ic_home_fill);
				tv_tab_home.setTextColor(getResources().getColor(R.color.colorPrimary));

				iv_tab_car.setImageResource(R.mipmap.ic_car_empty);
				tv_tab_car.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_type.setImageResource(R.mipmap.ic_type_empty);
				tv_tab_type.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_mine.setImageResource(R.mipmap.ic_mine_empty);
				tv_tab_mine.setTextColor(getResources().getColor(R.color.txt_gray));
				break;
			case 1:
				iv_tab_car.setImageResource(R.mipmap.ic_car_fill);
				tv_tab_car.setTextColor(getResources().getColor(R.color.colorPrimary));

				iv_tab_type.setImageResource(R.mipmap.ic_type_empty);
				tv_tab_type.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_mine.setImageResource(R.mipmap.ic_mine_empty);
				tv_tab_mine.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_home.setImageResource(R.mipmap.ic_home_empty);
				tv_tab_home.setTextColor(getResources().getColor(R.color.txt_gray));

				break;
			case 2:

				iv_tab_type.setImageResource(R.mipmap.ic_type_fill);
				tv_tab_type.setTextColor(getResources().getColor(R.color.colorPrimary));

				iv_tab_car.setImageResource(R.mipmap.ic_car_empty);
				tv_tab_car.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_mine.setImageResource(R.mipmap.ic_mine_empty);
				tv_tab_mine.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_home.setImageResource(R.mipmap.ic_home_empty);
				tv_tab_home.setTextColor(getResources().getColor(R.color.txt_gray));

				break;
			case 3:

				iv_tab_mine.setImageResource(R.mipmap.ic_mine_fill);
				tv_tab_mine.setTextColor(getResources().getColor(R.color.colorPrimary));
				iv_tab_car.setImageResource(R.mipmap.ic_car_empty);
				tv_tab_car.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_home.setImageResource(R.mipmap.ic_home_empty);
				tv_tab_home.setTextColor(getResources().getColor(R.color.txt_gray));

				iv_tab_type.setImageResource(R.mipmap.ic_type_empty);
				tv_tab_type.setTextColor(getResources().getColor(R.color.txt_gray));


				break;
		}
	}

	@Override
	public void onPageScrollStateChanged(int i) {

	}
}
